**** FIGURE 3 

use "$dir/data/outputs/ALP1forestimation_primkeys", clear
 gen experiment1 = 1
 append using "$dir/data/outputs/ALP2forestimation_primkeys"
 
 gen ownshare =  self/self_max 
label var ownshare "Budget share spent on self"
bys prim_key: egen avownshare1=mean(ownshare) if experiment1 ==1 
label var avownshare1 "Average share of budget spent on self in 2013"
bys prim_key: egen avownshare2=mean(ownshare) if experiment1 ==. 
label var avownshare2 "Average share of budget spent on self in 2016"
bys prim_key: egen sdownshare1=sd(ownshare) if experiment1 ==1 
bys prim_key: egen sdownshare2=sd(ownshare) if experiment1 ==. 
foreach var in avownshare1 avownshare2 sdownshare1 sdownshare2{
bys prim_key (`var'): replace `var' = `var'[1] if `var' ==. 
}
gen tokenshare = (self / (self+other))
 gen expshare = tokenshare*self_max/100

label var expshare "Budget share spent on self"
bys prim_key: egen expshare1=mean(expshare) if experiment1 ==1 
label var expshare1 "Average share of budget spent on self in 2013"
bys prim_key: egen expshare2=mean(expshare) if experiment1 ==. 
label var expshare2 "Average share of budget spent on self in 2016"
bys prim_key: egen sdexpshare1=sd(expshare) if experiment1 ==1 
bys prim_key: egen sdexpshare2=sd(expshare) if experiment1 ==. 
foreach var in expshare1 expshare2 sdexpshare1 sdexpshare2{
bys prim_key (`var'): replace `var' = `var'[1] if `var' ==. 
}


keep prim_key sdownshare1 sdownshare2 sdexpshare2 sdexpshare1 expshare2 expshare1
duplicates drop  
merge 1:1 prim_key using "$dir/data/outputs/ALPalldatafinal.dta"
drop if _m ==1
drop _m 
keep if alpha2!=. & se12!=. & rho2!=. & se22!=.
keep if complete1 ==1 & complete2 ==1

rename se11 se_alpha1 
rename se21 se_rho1
rename se12 se_alpha2
rename se22 se_rho2

* indicators for statistically significant changes
gen pval_alpha = 2*normal(-1*(abs((alpha1 - alpha2) / sqrt(se_alpha1^2 + se_alpha2^2))))
gen sig_alpha = pval_alpha<0.05 

gen pval_rho = 2*normal(-1*(abs((rho1 - rho2) / sqrt(se_rho1^2 + se_rho2^2))))
gen sig_rho = pval_rho<0.05 
replace pval_rho = . if rho1==-20 | rho2==-20
replace sig_rho = . if rho1==-20 | rho2==-20

replace alpha1 = 0.4 if alpha1<0.4
replace alpha2 = 0.4 if alpha2<0.4
replace rho1 = -2 if rho1<-2
replace rho2 = -2 if rho2<-2


gen pval_ownshare = 2*normal(-1*(abs((avownshare1 - avownshare2) / sqrt((sdownshare1^2 + sdownshare2^2)/50))))
gen sig_ownshare = pval_ownshare<0.05 



** alpha figure

twoway (lpolyci alpha2 alpha1 if alpha1>=0.4 & alpha2>=0.4, color(gs12*0.5)) ///
 (lpoly alpha2 alpha1 if alpha1>=0.4 & alpha2>=0.4, lcolor(gs2) lwidth(vthin)) ///
 (scatter alpha2 alpha1 if sig_alpha==0 & alpha1>=0.4 & alpha2>=0.4, mcolor(midgreen) msymbol(Oh) mlwidth(thin)) ///
 (scatter alpha2 alpha1 if sig_alpha==1 & alpha1>=0.4 & alpha2>=0.4, mcolor(midblue) msymbol(th) mlwidth(thin)), ///
 legend(off)  xlabel(0.4(0.1)1, grid)  ylabel(0.4(0.1)1, grid) fxsize(100) fysize(100) /// 
 ytitle("Estimated {&alpha} in 2016") xtitle("Estimated {&alpha} in 2013") saving(alphafig, replace)

 twoway histogram alpha1, fraction xsca(alt) xlabel(0.4(0.1)1, grid labsize(small)) ylabel(0(.05).15, grid labsize(small)) ///
 xlabel(, grid gmax) lcolor(black) xtitle(" ") fcolor(midblue) lwidth(vthin) saving(hx, replace) fysize(25)

twoway histogram alpha2, fraction ysca(alt ) xlabel(0(.05).15, grid labsize(small)) ylabel(0.4(0.1)1, grid labsize(small)) ///
 lcolor(black) fcolor(midblue)   ytitle(" ")lwidth(vthin) horiz saving(hy, replace) fxsize(25)

graph combine hx.gph alphafig.gph hy.gph, hole(2) imargin(0 0 0 0)  graphregion(margin(l=22 r=22)) 
graph export "$dir/tables-and-figures/summarize-alpha-changes.pdf", replace


** rho figure


forval x = 1/2 {
gen t_alpha_fair`x' = abs(alpha`x' - 0.5)/se_alpha`x'
gen t_fairminded`x' = (t_alpha_fair`x'<=1.65)
gen t_alpha_self`x' = abs(alpha`x' - 1)/se_alpha`x'
gen t_selfish`x' = (t_alpha_self`x'<=1.28)
gen tempchange`x' = 1 if t_selfish`x'==1 & t_fairminded`x'==1
replace t_selfish`x' = 0 if tempchange`x'==1 
replace t_fairminded`x' = 0 if tempchange`x'==1
drop tempchange`x'
gen tstat_rho`x' = rho`x'/se_rho`x'
gen t_eff_focus`x' = (tstat_rho`x'>=1.28)
gen t_eq_focus`x' = (tstat_rho`x'<=-1.28)
gen t_intermediate`x' = t_eff_focus`x'==0 & t_eq_focus`x'==0
gen t_s_intermediate`x' = t_fairminded`x'==0 & t_selfish`x'==0 

}

gen flag = t_selfish1 ==1 | t_selfish2 ==1 


preserve
keep if flag == 0
twoway (lpolyci rho2 rho1 if rho1>=-2 & rho2>=-2, color(gs12*0.5)) ///
 (lpoly rho2 rho1 if rho1>=-2 & rho2>=-2, lcolor(gs2) lwidth(vthin)) ///
 (scatter rho2 rho1 if sig_rho==0 & rho1>=-2 & rho2>=-2, mcolor(midgreen) msymbol(Oh) mlwidth(thin)) ///
 (scatter rho2 rho1 if sig_rho==1 & rho1>=-2 & rho2>=-2, mcolor(midblue) msymbol(th) mlwidth(thin)), ///
 legend(off) xlabel(-2(0.5)1, grid)  ylabel(-2(0.5)1, grid)  fxsize(100) fysize(100) /// 
  ytitle("Estimated {&rho} in 2016") xtitle("Estimated {&rho} in 2013") saving(rhofig, replace) 
  
  twoway histogram rho1, fraction xsca(alt) xlabel(-2(0.5)1, grid labsize(small)) ylabel(0(.1).3, grid labsize(small)) ///
 xlabel(, grid gmax) lcolor(black) xtitle(" ") fcolor(midblue) lwidth(vthin) saving(hx, replace) fysize(25)

twoway histogram rho2, fraction ysca(alt ) xlabel(0(.1).3, grid labsize(small)) ylabel(-2(0.5)1, grid labsize(small)) ///
 lcolor(black) fcolor(midblue)   ytitle(" ")lwidth(vthin) horiz saving(hy, replace) fxsize(25)

 graph combine hx.gph rhofig.gph hy.gph, hole(2) imargin(0 0 0 0)  graphregion(margin(l=22 r=22)) 
 graph export "$dir/tables-and-figures/summarize-rho-changes.pdf", replace
restore 

twoway (lpolyci avownshare2 avownshare1, color(gs12*0.5)) ///
 (lpoly avownshare2 avownshare1 , lcolor(gs2) lwidth(vthin)) ///
 (scatter avownshare2 avownshare1 if sig_ownshare==0 , mcolor(midgreen) msymbol(Oh) mlwidth(thin)) ///
 (scatter avownshare2 avownshare1 if sig_ownshare==1 , mcolor(midblue) msymbol(th) mlwidth(thin)), ///
 legend(off) xlabel(0(0.1)1, grid)  ylabel(0(0.1)1, grid)  fxsize(100) fysize(100)  /// 
  ytitle("Share of tokens to self in 2016") xtitle("Share of tokens to self in 2013") saving(ownsharefig, replace)
  
  twoway histogram avownshare1, fraction xsca(alt) xlabel(0(0.1)1, grid labsize(small)) ylabel(0(.05).15, grid labsize(small)) ///
 xlabel(, grid gmax) lcolor(black) xtitle(" ") fcolor(midblue) lwidth(vthin) saving(hx, replace) fysize(25)

twoway histogram avownshare2, fraction ysca(alt ) xlabel(0(.05).15, grid labsize(small)) ylabel(0.4(0.1)1, grid labsize(small)) ///
 lcolor(black) fcolor(midblue)   ytitle(" ")lwidth(vthin) horiz saving(hy, replace) fxsize(25)

  
   graph combine hx.gph ownsharefig.gph hy.gph, hole(2) imargin(0 0 0 0)  graphregion(margin(l=20 r=20)) 

 graph export "$dir/tables-and-figures/summarize-tokenshare-changes.pdf", replace

 
 
erase alphafig.gph
erase rhofig.gph
erase ownsharefig.gph
erase hx.gph
erase hy.gph


 
